package pacman.entries.pacman.meta_graph;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

import pacman.game.Game;

public abstract class MetaGraphEvaluator {

	// ___________________________________________ PUBLIC
	
	public MetaGraphEvaluator() {
		InitFeatures();
		InitWeightVectors();
	}
	
	public float Evaluate(Game game, MetaGraphNode object) {
		
		if (object == null)
			return 0.0f;
		
		float score = 0.0f;
		
		for (int i = 0; i < m_NodeFeatures.size(); i++)
			score += m_NodeFeatureWeights[i]* m_NodeFeatures.get(i).Evaluate(object, game);
		
		return score;
	}
	
	public float Evaluate(Game game, MetaGraphEdge object) {
		
		if (object == null)
			return 0.0f;
		
		float score = 0.0f;
		
		for (int i = 0; i < m_EdgeFeatures.size(); i++)
			score += m_EdgeFeatureWeights[i]* m_EdgeFeatures.get(i).Evaluate(object, game);
		
		return score;
	}
	
	public float Evaluate(Game game, MetaGraphPath object) {
		
		if (object == null)
			return 0.0f;
		
		float score = 0.0f;
		
		for (int i = 0; i < m_PathFeatures.size(); i++)
			score += m_PathFeatureWeights[i]* m_PathFeatures.get(i).Evaluate(object, game);
		
		return score;
	}
	
	// ___________________________________________ PROTECTED
	
	protected List<IMetaGraphFeature> m_NodeFeatures = new ArrayList<IMetaGraphFeature>();
	protected List<IMetaGraphFeature> m_EdgeFeatures = new ArrayList<IMetaGraphFeature>();
	protected List<IMetaGraphFeature> m_PathFeatures = new ArrayList<IMetaGraphFeature>();
	
	protected abstract void InitFeatures();
	
	// ___________________________________________ PRIVATE
	
	private float[] m_NodeFeatureWeights;
	private float[] m_EdgeFeatureWeights;
	private float[] m_PathFeatureWeights;
	
	private void InitWeightVectors() {
		m_NodeFeatureWeights = new float[m_NodeFeatures.size()];
		m_EdgeFeatureWeights = new float[m_EdgeFeatures.size()];
		m_PathFeatureWeights = new float[m_PathFeatures.size()];

		Arrays.fill(m_NodeFeatureWeights, 1.0f);
		Arrays.fill(m_EdgeFeatureWeights, 1.0f);
		Arrays.fill(m_PathFeatureWeights, 1.0f);
	}
	
}
